package com.engine;

import java.awt.Dimension;
import java.beans.PropertyChangeListener;

import javax.swing.JPanel;

import de.humatic.dsj.DSCapture;
import de.humatic.dsj.DSFilterInfo;
import de.humatic.dsj.DSFiltergraph;
import de.humatic.dsj.DSJUtils;

public class DVDPanelSDJ extends JPanel implements Runnable, PropertyChangeListener
{
	/**
	 * 
	 */
	
	private DSCapture graph;
	private static final long serialVersionUID = 1L;

	public DVDPanelSDJ()
	{
		createGraph();
	}
	
	public void createGraph() {

		/** queryDevices returns video device infos in slot 0 / audio device infos in slot 1 **/
		DSFilterInfo[][] dsi = DSCapture.queryDevices();
		/** this sample only uses video **/
		graph = new DSCapture(DSFiltergraph.DD7, dsi[0][0], false, DSFilterInfo.doNotRender(), this);
		graph.setPreferredSize(this.getPreferredSize());
		graph.setMaximumSize(this.getMaximumSize());
		final DSCapture.CaptureDevice avd = ((DSCapture)graph).getActiveVideoDevice();
		
		int iCross=Integer.parseInt(ReadConfig.GET("CROSSBAR_ID"));
		avd.connectCrossBarPins(iCross, 0, true);
		/*
		if (avd != null) {
			int dialogs = avd.getSupportedDialogs();
			if ((dialogs & CaptureDevice.CROSSBAR_1) != 0) {
				avd.showDialog(DSCapture.CaptureDevice.CROSSBAR_1);
			}
		}
		*/
		add(java.awt.BorderLayout.CENTER, graph.asComponent());
		//add(java.awt.BorderLayout.SOUTH, new SwingMovieController(graph));
		
		
		int iWidth=Integer.parseInt(ReadConfig.GET("VIDEO_WIDTH"));
  	  	int iHeight=Integer.parseInt(ReadConfig.GET("VIDEO_HEIGHT"));
  	  	
  	  	this.setPreferredSize(new Dimension(iWidth,iHeight));
  	  	graph.setPreferredSize(new Dimension(iWidth,iHeight));
  	  	/*
		javax.swing.JFrame jf = new javax.swing.JFrame("Device control");

		jf.setLayout(new java.awt.GridLayout(0,1));

		if (graph.getActiveVideoDevice() != null && graph.getActiveVideoDevice().getControls() != null) {

			for (int i = CaptureDeviceControls.BRIGHTNESS; i < CaptureDeviceControls.LT_FINDFACE; i++) try { jf.add(graph.getActiveVideoDevice().getControls().getController(i, 0, true)); }catch (Exception ex){}

		}

		if (graph.getActiveAudioDevice() != null) for (int i = CaptureDeviceControls.MASTER_VOL; i < CaptureDeviceControls.TREBLE; i++) try { jf.add(graph.getActiveAudioDevice().getControls().getController(i, 0, true)); }catch (Exception ex){}

		if (jf.getContentPane().getComponentCount() == 0) return;

		jf.pack();

		jf.setVisible(true);
		*/
	}

	public void propertyChange(java.beans.PropertyChangeEvent pe) {

		switch(DSJUtils.getEventType(pe)) {

		}

	}
@Override
public void run() {
	// TODO Auto-generated method stub
	
}
}
